import { ICommonParams, IHeaders } from '../../interfaces';
import { close, open } from '../_redis';
import { get_use_info, IRole } from './_get-user-info';

/**
 * 获取除去当前角色的其他角色
 * @param msg 系统参数，fd.data.msg
 * @param headers 系统参数，fd.data.hearders
 * @param productid 项目productid
 * @param clienttype 端点类型，web：3,h5：2,xcx:9
 */
export default async function get_roles(msg: ICommonParams, headers: IHeaders, productid: string, clienttype: string) {
	const client = open();
	try {
		const cookie = msg.cookie;
		const sessionid = cookie.sessionid;
		const user_info = await get_use_info(client, headers.actionid, sessionid, headers.spaceid, productid, clienttype);
		const role_no = user_info.role_no;
		return user_info.roles.filter((item) => {
			return item.role_no !== role_no;
		}) as IRole[];
	} finally {
		close(client);
	}
}
